# Maintainer : Andrew Crerar <andrew (dot) crerar at gmail>
# Contributor: Rob McCathie <korrode at gmail>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Sarah Hay <sarahhay@mb.sympatico.ca>
# Contributor: Martin Sandsmark <martin.sandsmark@kde.org>
# Contributor: heaven <aheaven87 at gmail dot com>
# Contributor: graysky <graysky at archlinux dot us>
# Contributor: Arkham <arkham at archlinux dot us>
# Contributor: MacWolf <macwolf at archlinux dot de>

DEBUG=1
#avoid making compressed packages? aka faster
PKGEXT='.pkg.tar'

_name=vlc
pkgname=vlc-git
pkgver=r2.2.0.git.3996.g68827bc
pkgrel=1
pkgdesc="A multi-platform MPEG, VCD/DVD, and DivX player (GIT Version)"
arch=('i686' 'x86_64')
url="http://www.videolan.org/vlc/"
license=('LGPL2.1' 'GPL2')
depends=('a52dec' 'faad2' 'ffmpeg' 'libdca' 'libdvbpsi'
         'libdvdnav' 'libmad' 'libmatroska' 'libmpcdec' 'libmpeg2'
         'libproxy' 'libshout' 'libtar' 'libtiger' 'libupnp'
         'libxinerama' 'libxpm' 'lua' 'qt4' 'sdl_image'
         'taglib' 'xcb-util-keysyms' 'zvbi')
makedepends=('aalib' 'flac' 'git' 
#'gnome-vfs' 'kdelibs'
             'libavc1394' 
#             'libbluray' 
#             'libcaca' 
#             'libdc1394' 
#             'libdvdcss'
             'libgme' 'libgoom2' 'libmtp' 'libnotify' 'librsvg'
             'libssh2' 
#             'lirc-utils' 
#'live-media'
'mesa' 'opus'
             'portaudio' 'projectm' 'twolame' 'vcdimager' 
#             'xosd'
             )
optdepends=('aalib: for ASCII art plugin'
            'avahi: for service discovery using bonjour protocol'
            'flac: for Free Lossless Audio Codec plugin'
            'gnome-vfs: for GNOME Virtual File System support'
            'kdelibs: KDE Solid hardware integration'
            'libavc1394: for devices using the 1394ta AV/C'
            'libbluray: for Blu-Ray support'
            'libcaca: for colored ASCII art video output'
            'libcdio: for audio CD playback support'
            'libdc1394: for IEEE 1394 plugin'
            'libdvdcss: for decoding encrypted DVDs'
            'libgme: for libgme plugin'
            'libgoom2: for libgoom plugin'
            'libmtp: for MTP devices support'
            'libnotify: for notification plugin'
            'librsvg: for SVG plugin'
            'libssh2: for sftp support'
            'libva-intel-driver: back-end for intel cards'
            'libva-vdpau-driver: vdpau back-end for nvidia'
            'lirc-utils: for lirc plugin'
            'lua-socket: for http interface'
            'ncurses: for ncurses interface support'
            'opus: for opus support'
            'portaudio: for portaudio support'
            'projectm: for ProjectM visualisation plugin'
            'smbclient: for SMB access plugin'
            'ttf-dejavu: for subtitle font'
            'ttf-freefont: for subtitle font'
            'twolame: for TwoLAME mpeg2 encoder plugin'
            'vcdimager: navigate VCD with libvcdinfo')
conflicts=("${_name}" 'vlc-dev' 'vlc-plugin' 'vlc-stable-git')
provides=("${_name}=${pkgver}")
backup=('usr/share/vlc/lua/http/.hosts'
        'usr/share/vlc/lua/http/dialogs/.hosts')
options=('!emptydirs' '!strip')
install="${_name}.install"
patch1='fix_transform_filter.patch'
patch2='workaround_orange_bouncing_bar.patch'
#patch3='0001-Add-dpms-module-to-switch-it-off-while-playing.patch'
patch4='0001_allow_screensaver_and_power_management_while_video_is_paused.patch'
#patch5='0003_d3d_dangling_symbol.patch'
source=('git+https://github.com/videolan/vlc.git'
#'git://git.videolan.org/vlc.git' #no https
"$install"
"$patch1"
"$patch2"
#"$patch3"
"$patch4"
#"$patch5"
)
sha512sums=('SKIP'
            '0051ff0d454bbed09bc6bdde1b8cd2f1187ef9e0f22f6b03878deb2203ea4bb963d54276253de323db6e519d243d2140799d062425e6b6d496223885188a2c78'
            '5bb0b0d0a0df7e132c1b0e362af1fb51366846a5c56829bbe1617c55606e3cfa2dace4811ea60d12719d99e6e21d12053d730c2bb85a22a2b1c1ede42d9c8e90'
            'fa0a8665ec61c4d493d51f7c2ecde101a89852ac88e50717627d612d5c5215d04d90ad8b4be7931e64dfe1137a34bd92eda4dfb12a4158407eba5d474f9ce388'
            '0dd00cdfd60ecf1c6988b52803cc98e0b5f98cfbc10afa066b053fc9c8cf62500815876fcf37aa8067d3d99414a0218a1b48991cfe5644a6f11f0ca098d2b03a')

if test -n "$DEBUG" -a "$DEBUG" -eq "1" ; then
  dbg="-g3 -DDEBUG -O1 -fvar-tracking-assignments"
  export CFLAGS+=" $dbg"
  export CXXFLAGS+=" $dbg"
  export CPPFLAGS+=" $dbg"
  msg2 "CFLAGS=$CFLAGS"
  msg2 "CXXFLAGS=$CXXFLAGS"
  msg2 "CPPFLAGS=$CPPFLAGS"
  #options-=('strip')
  options+=('!strip')
fi

pkgver() {
  cd "${srcdir}/${_name}"
  git describe --long | sed -r 's/([^-]*-g)/r\1/;s/-/./g'
}

prepare() {
  cd "${srcdir}/${_name}"

  sed -i -e 's:truetype/ttf-dejavu:TTF:g' modules/visualization/projectm.cpp

  patch -Np1 -i "../${patch1}"
  patch -Np1 -i "../${patch2}"
#  patch -Np1 -i "../${patch3}"
  patch -Np1 -i "../${patch4}"
#  patch -Np1 -i "../${patch5}"

  find . -name .deps -exec rm -rf \{\} \;
  ./bootstrap
#  CFLAGS+=" -I/usr/include/samba-4.0" CPPFLAGS+=" -I/usr/include/samba-4.0" \

cat >/dev/null <<\EOF
  ./configure --prefix=/usr \
--sysconfdir=/etc \
--disable-rpath \
--enable-faad \
--enable-nls \
--enable-realrtsp \
--disable-glx \
--disable-lua \
RCC=/usr/bin/rcc-qt4
EOF

#  configme
#}
#
#configme() {
#  --disable-atmo \ nolonger exists
##cat >/dev/null <<\EOF
  ./configure --disable-rpath \
  --enable-option-checking \
  --enable-dependency-tracking \
  --enable-libtool-lock \
  --without-libintl-prefix \
  --disable-winstore-app \
  --disable-vdpau \
  --enable-dbus \
  --enable-debug \
  --disable-gprof \
  --disable-cprof \
  --disable-coverage \
  --disable-optimize-memory \
  --disable-run-as-root \
  --disable-sout \
  --disable-lua \
  --disable-httpd \
  --disable-vlm \
  --disable-addonmanagermodules \
  --disable-dc1394 \
  --disable-dv1394 \
  --disable-linsys \
  --disable-dvdread \
  --disable-dvdnav \
  --disable-bluray \
  --disable-opencv \
  --disable-smbclient \
  --disable-dsm \
  --disable-sftp \
  --disable-v4l2 \
  --disable-decklink \
  --disable-gnomevfs \
              --enable-vcdx \
  --disable-vcd \
  --disable-libcddb \
  --enable-screen \
  --disable-vnc \
  --disable-freerdp \
  --disable-realrtsp \
  --disable-macosx-eyetv \
  --disable-macosx-qtkit \
  --disable-macosx-avfoundation \
  --disable-asdcp \
              --enable-faad \
              --enable-opus \
  --enable-mpg123 \
  --enable-gst-decode \
  --disable-quicktime \
  --with-x \
  --enable-gles2 \
              --disable-aa \
              --disable-caca \
  --enable-pulse \
  --disable-sndio \
  --enable-samplerate \
  --disable-kai \
  --disable-chromaprint \
  --disable-chromecast \
  --enable-qt \
  --disable-skins2 \
  --disable-libtar \
  --disable-macosx \
              --disable-lirc \
              --enable-ncurses \
  --disable-goom \
  --disable-projectm \
  --disable-vsxu \
  --disable-bonjour \
  --disable-udev \
  --disable-mtp \
              --disable-upnp \
  --enable-gnutls \
  --disable-update-check \
  --enable-vlc \
  --disable-macosx-vlc-app \
              --disable-nls \
              --prefix=/usr \
              --sysconfdir=/etc \
              RCC=/usr/bin/rcc-qt4
#              LUAC=/usr/bin/luac  LUA_LIBS="`pkg-config --libs lua`" \
#EOF

}

build() {
  cd "${srcdir}/${_name}"

#  configme


  make
}

package() {
  cd "${srcdir}/${_name}"

  make DESTDIR="${pkgdir}" install

  for res in 16 32 48 128; do
    install -D -m644 "${srcdir}/${_name}/share/icons/${res}x${res}/vlc.png" \
                     "${pkgdir}/usr/share/icons/hicolor/${res}x${res}/apps/vlc.png"
  done
}
